package com.sky.api.config;

import com.sky.api.client.fallback.ItemClientFallbackFactory;
import com.sky.context.BaseContext;
import feign.Logger;
import feign.RequestInterceptor;
import org.springframework.context.annotation.Bean;

public class DefaultFeignConfig {

    @Bean
    public Logger.Level feignLogLevel(){
        return Logger.Level.FULL;
    }

    @Bean
    public RequestInterceptor uerInfoRequestInterceptor(){
        return requestTemplate -> {
            Long userId = BaseContext.getCurrentId();
            if(userId==null)return;
            requestTemplate.header("user-info",userId.toString());
        };
    }

    @Bean
    public ItemClientFallbackFactory itemClientFallbackFactory1(){
        return new ItemClientFallbackFactory();
    }
}
